package org.seedltd.upms.controller.sys;

import java.util.List;
import java.util.Map;

import org.seedltd.core.base.BaseController;
import org.seedltd.core.utils.Assert;
import org.seedltd.core.utils.StringUtils;
import org.seedltd.log.service.LogService;
import org.seedltd.upms.model.sys.form.SysLogSearchForm;
import org.springframework.web.bind.annotation.*;

import com.google.common.collect.Maps;

import lombok.AllArgsConstructor;

/**
 *
 * 参数管理控制器
 * 
 * @author laizuan
 * @version 1.0
 * @since 2021/07/19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sysLog")
public class SysLogController extends BaseController<LogService> {

    /**
     * 获取详情
     * 
     * @param id
     *            主键
     * @return 日志
     */
    @GetMapping(value = "/get")
    public org.seedltd.log.SysLog get(Long id) {
        Assert.notNull(id, "参数不能为空");
        return baseService.getById(id);
    }

    /**
     * 列表
     * 
     * @param searchForm
     *            查询条件
     * @return 参数管理列表集合
     */
    @PostMapping(value = "/list")
    public Map<String, Object> page(@RequestBody SysLogSearchForm searchForm) {
        String type = searchForm.getType();
        String userName = searchForm.getUserName();
        String description = searchForm.getUserName();
        Map<String, Object> param = Maps.newHashMap();
        if (StringUtils.isNotBlank(type)) {
            param.put("type", type);
        }
        if (StringUtils.isNotBlank(userName)) {
            param.put("userName", userName);
        }
        if (StringUtils.isNotBlank(description)) {
            param.put("description", description);
        }
        param.put("startTime", searchForm.getStartTime());
        param.put("endTime", searchForm.getEndTime());

        List<String> column = List.of("type", "id", "userName", "description", "method", "ip", "ua", "exception",
            "startTime", "finishTime");
        return baseService.listPage(searchForm.getStart(), searchForm.getSize(), param, column);
    }
}